<template>
  <div class="index-container">
    <div class="main-header clearfix">
      <el-row>
       <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
          <el-button type="primary"  icon="el-icon-plus" class="sureBtn"  size="medium"  @click="handleAdd" > 添加药品出库</el-button>
        </el-col>
        <el-col :xs="16" :sm="16" :md="16" :lg="16" :xl="16">
         <div class="search fr">
             <div>
               <el-input  v-model="searchForm.title" size="medium"  placeholder="老人姓名"></el-input>
             </div>
             <div>
               <el-input  v-model="searchForm.code" size="medium"  placeholder="批准文号"></el-input>
             </div>
             <div>
              <el-select v-model="searchForm.stock" clearable placeholder="库存" filterable size="medium"  style="width: 100%;">
                <el-option label="正常" value="1"></el-option>
                <el-option label="无库存" value="2"></el-option>
              </el-select>
             </div>
             <div style="margin-right: 5px;">
               <el-checkbox v-model="searchForm.guoqi" true-label="1">即将过期药品</el-checkbox>
             </div>
             <el-button size="medium"   type="primary"   icon="el-icon-search"  class="fr"    @click="handleSearch" > 搜索</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="main-content" style="height: calc(100vh - 250px);">
      <main-table
        :columns="tableColumns"
        :data="tableList"
        :loading="loading"
        :pagination="pagination"
        wrapper-height="calc(100% - 73px)"
        height="100%"
        @getData="fetchTableList"
      >
      <el-table-column slot="status" label="状态" width="80" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1" type="success">正常</el-tag>
          <el-tag v-else type="danger">禁用</el-tag>
        </template>
      </el-table-column>

       <el-table-column slot="action" fixed="right" label="操作" align="center" >
         <template slot-scope="scope">
           <el-button size="mini" type="success" @click="edit(scope.row)">查看出库单</el-button>
         </template>
       </el-table-column>
      </main-table>
    </div>

    <el-dialog
      title="添加药品出库"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="100%">
      <medicineRemove    @close-dialog-and-refresh="closeDialogAndRefresh"></medicineRemove>
    </el-dialog>
    <el-dialog
    title="出库单"
      :visible.sync="dialogVisibleTwo"
      :close-on-click-modal="false"
      width="80%">
      <removeInfo :table-data="tableData"   @close-dialog-and-refresh="closeDialogAndRefresh" ></removeInfo>
    </el-dialog>
  </div>
</template>
<script>
  import mainTable from "@/components/main-table/index";
  import * as APIMedicalCare from '@/api/medicalCare';
  import medicineRemove from './components/medicine-remove';
  import removeInfo from "./components/remove-info.vue";
  export default {
    name: "Remove",
    components: {
      mainTable,
      medicineRemove,
      removeInfo
    },
    data() {
      return {
        loading: false,
        title: '添加图标',
        dialogVisible: false,
        dialogVisibleTwo:false,
        dialogStocklogVisible: false,   // 库存记录
        ruleForm: {},
        searchForm: {
           page: 1
        },
        tableList:[],
        pagination: {
          current: 1,
          size: 10,
          total: 0
        },
        tableColumns: [
         {
           index: true,
           fixed: true
         },
         {
           prop: 'output_id',
           label: '出库单号',
           align:'center'
         },
         {
           prop: 'note',
           label: '备注',
           align:'center'
         },
         {
           prop: 'update_time',
           label: '最后更新时间',
           align:'center'
         },
         {
           prop: 'create_time',
           label: '出库时间',
           align:'center'
         },
        {
          slot:'status'
        },
         {
          slot:'action'
         },
        ],
        tableData:[]
      };
    },
    created() {},
    beforeDestroy() {},
    mounted() {
      this.fetchTableList();
    },
    methods: {

      handleSearch() {
        this.pagination = {
          current: 1,
          size: 10,
          total: 0
        }
        this.fetchTableList({ page: 1 })
      },
      fetchTableList(pageObj) {
        this.loading = true
        this.searchForm = {
          ...this.searchForm,
          ...pageObj
        }
        APIMedicalCare.removeInfoList(this.searchForm).then((resp) => {
          if (resp.code == 200) {
            const { list = [], total = 0 } = resp.data;
            this.tableList = list || []
            console.log( this.tableList)
            this.pagination.total = total;
          }
        }).finally(() => {
         this.loading = false
        });
      },
      edit (row) {
        this.dialogVisibleTwo = true
        let params = {
          output_id:row.output_id
        }
        APIMedicalCare.removeResearchInfo(params).then(res=>{
          this.tableData=res.data.info
          console.log(this.tableData);
        })
      },
      handleAdd() {
        this.dialogVisible = true;
      },
      closeDialogAndRefresh() {
      // 关闭模态框
      this.dialogVisible = false;
      this.fetchTableList()
    },
    },
  };
</script>
<style lang="scss" scoped>
  .index-container {
    box-sizing: border-box;
    width: 100%;
    padding: 0 30px !important;
    margin: 0 !important;
    background: #fff !important;

    .main-header {
      padding-top: 4px;
      margin-bottom: 24px;

      .search {
        display: inline-block;

        .search-title {
          flex: 0 0 48px;
          width: 48px;
          font-size: 16px;
          line-height: 36px;
          color: #333;
        }
      }

      .search > div {
        display: inline-block;
        margin-left: 20px;
      }
    }
    .task-icon-img{
      width: 80px;
      height: 80px;
    }
  }

  .form-footer {
    padding-left: 100px;
  }

  .dialog-main {
    .table-do {
      margin-bottom: 15px;
    }

    ::v-deep {
      th {
        .cell {
          color: #fff;
        }
      }
    }
  }
</style>
